﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <title>教师注册</title>
    <link rel="stylesheet" type="text/css" href="/ViewMob/css/default.css">
    <link href="/ViewMob/css/reset.css" rel="stylesheet" type="text/css">
    <link href="/ViewMob/js/layer/need/layer.css" rel="stylesheet" />
    <script src="/ViewMob/js/layer/layer.m.js"></script>
    <script src="/ViewMob/js/zepto.min.js"></script>
    <script src="/ViewMob/js/avalon.mobile.js"></script>
    <script src="/ViewMob/js/ComFunJS.js"></script>
    <script src="/ViewMob/js/zepto.md5.js"></script>
    <script>
        model = avalon.define({
            $id: "Register",
            modelData: { "TeacherName": "", "Phone": "", "Pasword": "", "usertype": 0 },
            dxyzm: "",
            sendYZM: function (dom) { //获取验证码
                $(dom).prop("disabled", true); 
                if (Times == 60) {
                    msg = "";
                    if (!model.modelData.Phone || !(/^1[3|4|5|8|7][0-9]\d{8}$/).test(model.modelData.Phone)) {
                        msg = "请输入正确的手机号";
                    }
                    $.ajaxSettings.async = false;
                    $.getJSON('/API/VIEWAPI.ashx?Action=Commanage_CHECKREGISTERPHONE', { P1: model.modelData.Phone }, function (resultData) {
                        if (resultData.ErrorMsg != "") {
                            msg = resultData.ErrorMsg;
                        }
                    })
                    if (!msg) {
                        Times = 60;
                        $(dom).val(Times + "秒后重新获取");
                        intervalId = setInterval(TimeDown, 1000);
                        $.ajax({
                            url: "/API/VIEWAPI.ashx?Action=Commanage_SENDCHKMSG&r=" + Math.random(),
                            type: "POST",
                            data: { P1: model.modelData.Phone },
                            async: false,
                            success: function (result) {
                                var jsonresult = $.parseJSON(result);
                                if (jsonresult.ErrorMsg == "") {
                                    var exp = new Date();
                                    exp.setTime(exp.getTime() + 30 * 60 * 1000);
                                    document.cookie = "chkcode=" + escape(jsonresult.Result) + ";expires=" + exp.toGMTString() + ";path=/";
                                    document.cookie = "chkphone=" + escape(model.modelData.Phone) + ";expires=" + exp.toGMTString() + ";path=/";
                                } else {
                                    ComFunJS.winwarning(msg);
                                }
                            },
                            error: function (xhr) {
                                ComFunJS.winwarning(msg);
                            }
                        });
                    } else {

                        ComFunJS.winwarning(msg);
                    }
                }
            }, SaveForm: function (dom) {

                $(dom).text("正在提交，请稍等");
                $(dom).prop("disabled", true);
                if ($.trim(model.modelData.TeacherName) == "") {
                    msg = "请输入姓名";  
                }
                if ($.trim(model.modelData.Phone) == "") { 
                    msg = "请输入手机号"; 
                }
                if (!model.modelData.Phone || !(/^1[3|4|5|8|7][0-9]\d{8}$/).test(model.modelData.Phone)) {
                   
                    msg = "请输入正确的手机号";
                }
                if ($.trim(model.modelData.Pasword) == "") { 
                    msg = "请输入密码";
                    
                }
                if ($.trim(model.dxyzm) == "") {
                   msg = "请输入短信验证码";
                     
                }
                if ($.trim(model.dxyzm) != "") {
                    if ($.trim(model.dxyzm).length != 4) { 
                        msg = "请输入四位的验证码";
                    } else {

                        var arr, reg = new RegExp("(^| )chkcode=([^;]*)(;|$)");
                        if (arr = document.cookie.match(reg)) {
                            var ckc = unescape(arr[2]);
                            if ($.md5($.trim(model.dxyzm)).toUpperCase() == ckc) {
                                var arr1, reg1 = new RegExp("(^| )chkphone=([^;]*)(;|$)");
                                if (arr1 = document.cookie.match(reg1)) {
                                    var ckp = unescape(arr1[2]);
                                    if (ckp != model.modelData.Phone) { 
                                        msg = "验证码和手机号不匹配";
                                    }
                                }
                                else { 
                                    msg = "输入的验证码错误";
                                }
                            }
                            else { 
                                msg = "没有获取验证码或已过期";
                            }
                        } else { 
                            msg = "请输入正确的验证码";
                        }
                    } 
                }
                if (msg)
                {
                    ComFunJS.winwarning(msg);
                    $(dom).text("立即注册");
                    $(dom).removeAttr("disabled");
                    return;
                }
                $.post("/API/VIEWAPI.ashx?Action=Commanage_REGISTER&r=" + Math.random(), { "P1": JSON.stringify(model.modelData.$model) }, function (data) {
                    var data = $.parseJSON(data);
                    if (data.ErrorMsg == "") {
                        $(dom).text("立即注册");
                        $(dom).removeAttr("disabled");
                        ComFunJS.winsuccess("注册成功")
                    }
                    else {
                        $(dom).text("立即注册");
                        $(dom).prop("disabled", false);
                    }
                })
            }
        })
        var Times = 60;
        var intervalId;
        function TimeDown() {
            Times = Times - 1;
            if (Times == 0) {
                $(".yzm").val("重新获取");
                $(".yzm").prop("disabled",false);
                clearInterval(intervalId);
            }
            else {
                $(".yzm").val(Times + "秒后重新获取");
            }
        }
    </script>
</head>
<body style="display:table;width:100%" ms-controller="Register">
    <div class="form-box">
        <div class="logo-teacher tc">
            <img src="/ViewMob/images/tea.png">
        </div>
        <div class="input-panel">
            <input type="text" placeholder="姓名" ms-duplex="modelData.TeacherName">
        </div>
        <div class="input-panel">
            <input type="text" placeholder="手机号" ms-duplex="modelData.Phone">
        </div>
        <div class="input-panel">
            <input type="password" placeholder="密码" ms-duplex="modelData.Pasword">
        </div>

        <div class="input-panel">
            <div style="width:60%;float:left;height:100%;" class="left">
                <input type="text" placeholder="短信验证码" ms-duplex="dxyzm">
            </div>
            <div style="width:40%;float:right;height:100%;" class="right">
                <input type="button" value="获取验证码" ms-click="sendYZM(this)" class="yzm">
            </div>
        </div>
        <div class="input-panel-btn">
            <button ms-click="SaveForm(this)">
                注册 
            </button>
            <div class="login-zc">已有账号？<a href="UI_Login.html" external>去登陆</a></div>
        </div>
    </div>
</body>
</html>
